// 云函数入口文件
const cloud = require("wx-server-sdk");
cloud.init();
const db = cloud.database();

// 查找相应的用户数据
exports.main = async (event, context) => {
    if (typeof event.index !== "number" && event.index < 0)
        return { err: "index error", desc: "请在 index 字段填入您的位置" };
    // ! 权限：调用人必为 Manager
    const { result: InvokerIsManager } = await cloud.callFunction({
        name: "isManager",
        data: {
            UserOpenId: event.userInfo.openId,
        },
    });
    if (InvokerIsManager !== true)
        return {
            err: "permission denied.\n" + JSON.stringify(InvokerIsManager),
            desc: "没有权限",
        };
    const { data } = await db
        .collection("UnPublicXin")
        .skip(event.index * 100)
        .get();
    return data;
};
